
import { Net } from "../../../quick/core/net/Net";
import { Service } from "../../../quick/core/net/service/Service";
import { MainCmd, SUB_CMD_SYS } from "../protocol/CmdDefines";

/**
 * @description service公共基类
 */
export class CommonService extends Service {
    protected ip = "localhost";
    protected port = 3000;
    protected protocol: Net.Type = "ws"

    /**
    * @description 连接网络
    */
    public connect() {
        super.connect_server(this.ip, this.port, this.protocol);
    }

    /**
     * @description 发送心跳
     */
    protected sendHeartbeat() {
        //发送心跳
        if (this.heartbeat) {
            this.send(new this.heartbeat());
        } else {
            Log.e("请先设置心跳解析类型")
        }
    }
    /**
     * @description 是否为心跳消息
     */
    protected isHeartBeat(data: Message): boolean {
        //示例
        return data.cmd == String(MainCmd.CMD_SYS) + String(SUB_CMD_SYS.CMD_SYS_HEART)
    }
}